package gaileenchess;

import java.util.LinkedList;

public class Knight extends Piece
{
    public Knight(Common.Side s, int r, int c)
    {
        super(s, Type.KNIGHT, r, c);
    }
    
    public boolean isValidMove(Common.Side playerSide, Board board, Board.Position pos1, Board.Position pos2)
    {
        Board.Position diff = pos1.diff(pos2);
        return ((Math.abs(diff.row) == 2 && Math.abs(diff.column) == 1)
            || (Math.abs(diff.row) == 1 && Math.abs(diff.column) == 2));
    }

    public void getValidMoves(Common.Side playerSide, Board board, LinkedList<Board.Position.Move> pieces, boolean check, int player)
    {
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(1, 2)), check, player);
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(2, 1)), check, player);
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(-1, 2)), check, player);
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(-2, 1)), check, player);
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(-1, -2)), check, player);
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(-2, -1)), check, player);
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(1, -2)), check, player);
        getValidMovesCheckAndAdd(playerSide, board, pieces, getPosition().add(new Board.Position(2, -1)), check, player);
    }
}
